/******************************************************************************
 cnome: A C++ source "genes" discover. :-)

 See more details at:

   http://www.codeplex.com/cnome

 The original author site is at: http://www.alemosbarbosa.com/

 Copyright (c) 2008-2010 Alexandre Lemos Barbosa.
 Distributed under the MIT License. (See accompanying file LICENSE-MIT.txt 
 or at http://www.codeplex.com/cnome/license)
 ******************************************************************************/

#ifndef DIRECTIVE_CT_H
#define DIRECTIVE_CT_H

#include "directive_base.h"
#include "variables.h"

namespace cnome { namespace directive {
    struct ct_parser_gen;

    template <typename ParserT>
    struct ct
    :   public boost::spirit::classic::unary<ParserT, boost::spirit::classic::parser<ct<ParserT> > >
    {
        typedef ct<ParserT>                     self_t;
        typedef boost::spirit::classic::unary_parser_category           parser_category_t;
        typedef ct_parser_gen                   parser_generator_t;
        typedef boost::spirit::classic::unary<ParserT, boost::spirit::classic::parser<self_t> > base_t;

        ct(ParserT const& p)
        : base_t(p) {}

        template <typename ScannerT>
        typename boost::spirit::classic::parser_result<self_t, ScannerT>::type
        parse(ScannerT const& scan) const
        {
            typedef typename boost::spirit::classic::parser_result<self_t, ScannerT>::type result_t;
            return impl::drt_parser_parse<result_t>
                (*this, scan, scan);
        }

        const char* MyName() const { return "ct"; }

        template <typename ScannerT>
        inline void
        deriv_action_before_parse(
            ScannerT const& scan) const
        {
            var::l_typeDecl.push_back(var::typeDecl);
            var::typeDecl.clear();
        }

        template <typename ScannerT>
        inline void
        deriv_action_after_parse(
            ScannerT const& scan) const 
        {
            var::typeDecl = var::l_typeDecl.back();
            var::l_typeDecl.pop_back();
        }
    };

    //////////////////////////////////
    const drt_parser_gen<ct> clear_type_d = drt_parser_gen<ct>();

}} // namespace cnome { namespace directive {

#endif  // DIRECTIVE_CT_H
